package com.example.demo.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.example.demo.client.SmQryClient;
import com.example.demo.client.evt.cssmqry.role.QryRoleEvt;
import com.example.demo.client.evt.sysbasequery.LoginNameEvt;
import com.example.demo.client.evt.sysbasequery.QueryUserEvt;
import com.example.demo.client.vm.sysbasequery.MenuTreeVm;
import com.example.demo.client.vm.sysbasequery.QueryUserVm;
import com.example.demo.client.vm.sysbasequery.RoleTreeVm;
import com.ffcs.oss.common.utils.LocalMessageUtil;
import com.example.demo.domain.CsSmImportLogD;
import com.example.demo.enums.ExportListEnum;
import com.example.demo.enums.ImportEnum;
import com.example.demo.mapper.CsSmImportLogDMapper;
import com.example.demo.mapper.MenuMapper;
import com.example.demo.mapper.RoleMapper;
import com.ffcs.oss.param.out.ServiceResp;
import com.example.demo.security.SecurityUtils;
import com.example.demo.service.*;
import com.example.demo.web.rest.constant.ExportConstant;
import com.example.demo.web.rest.evt.NoticeSearchEvt;
import com.example.demo.web.rest.evt.log.LoginLogEvt;
import com.example.demo.web.rest.evt.log.QryOperateLogEvt;
import com.example.demo.web.rest.evt.log.QueryOperateLogEvt;
import com.example.demo.web.rest.util.ExcelExportUtil;
import com.example.demo.web.rest.vm.NoticeCodeList;
import com.example.demo.web.rest.vm.NoticeVm;
import com.google.common.collect.Lists;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.example.demo.web.rest.constant.ExportConstant.EXPORT_ROLE_MANAGE;
import static com.example.demo.web.rest.constant.ExportConstant.EXPORT_ROLE_PERMISSION;
import static com.example.demo.web.rest.util.ExcelExportUtil.getRow;


/**
 * Description:
 *
 * @Author zmf
 * @Date 2018/12/12  18:39
 */
@Service
@Transactional
public class ExcelServiceImpl implements ExcelService {
    protected Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private RoleService roleService;
    @Autowired
    private UserService userService;
    @Autowired
    private NoticeService noticeService;
    @Autowired
    protected SmQryClient baseQueryClient;
    @Autowired
    protected MenuMapper menuMapper;
    @Autowired
    protected RoleMapper roleMapper;
    @Autowired
    private LogService logService;
    @Autowired
    CsSmImportLogDMapper csSmImportLogDMapper;

    private String[][] strs = new String[200][10];


    @Override
    public void exportExcel(HttpServletRequest request, HttpServletResponse response, String[] strEname, String[] strCname, String exportFileName, String sheetName, Integer ExportType, String evtStr) throws Exception {
        //默认只导出一个sheet
        int exportSheetNum = 1;
        FileOutputStream outStream = null;
        //忽略前端分页传参
        int currNo = ExportConstant.EXPORT_ACTIVEPAGE;
        int currSize = ExportConstant.EXPORT_PAGESIZE;
        QueryUserEvt userEvt = new QueryUserEvt();
        QryRoleEvt roleEvt = new QryRoleEvt();
        NoticeSearchEvt noticeEvt = new NoticeSearchEvt();
        LoginLogEvt loginLogEvt = new LoginLogEvt();
        QueryOperateLogEvt queryOperateLogEvt = new QueryOperateLogEvt();
        List showList = new ArrayList();
        switch (ExportType) {
            case ExportConstant.EXPORT_TYPE_ROLE:
                roleEvt = JSONObject.parseObject(evtStr, QryRoleEvt.class);
                showList = roleService.getRoleTreeInfosExport(roleEvt);
                exportSheetNum = 2;
                break;
            case ExportConstant.EXPORT_TYPE_USER:
                userEvt = JSONObject.parseObject(evtStr, QueryUserEvt.class);
                userEvt.setPageNo(currNo);
                userEvt.setPageSize(currSize);
                userEvt.setCountTotal(true);
                userEvt.setLoginName(SecurityUtils.getCurrentUserLogin().get());
                showList = baseQueryClient.exportUser(userEvt).getBody().getRecords();
                parseUserList(showList);
                break;
            case ExportConstant.EXPORT_TYPE_NOTICE:
                noticeEvt = JSONObject.parseObject(evtStr, NoticeSearchEvt.class);
                noticeEvt.setPageNo(currNo);
                noticeEvt.setPageSize(currSize);
                showList = noticeService.selectInfos(noticeEvt);
                transNoticeCode(showList);
                break;
            case ExportConstant.EXPORT_TYPE_OPERATE_LOG_BY_AREA:
                showList = logService.countByArea(JSONObject.parseObject(evtStr, QryOperateLogEvt.class));
                break;
            case ExportConstant.EXPORT_TYPE_OPERATE_LOG_BY_COMPANY:
                showList = logService.countByCompany(JSONObject.parseObject(evtStr, QryOperateLogEvt.class));
                break;
            case ExportConstant.EXPORT_TYPE_OPERATE_LOG_BY_USER:
                showList = logService.countByUser(JSONObject.parseObject(evtStr, QryOperateLogEvt.class));
                break;
            case ExportConstant.EXPORT_TYPE_OPERATE_LOG_BY_FUN:
                showList = logService.countByFun(JSONObject.parseObject(evtStr, QryOperateLogEvt.class));
                break;
            case ExportConstant.EXPORT_TYPE_OPERATE_LOG_BY_BUSY:
                showList = logService.countByBusy(JSONObject.parseObject(evtStr, QryOperateLogEvt.class));
                break;
            case ExportConstant.EXPORT_TYPE_OPERATE_LOG_LIST:
                queryOperateLogEvt = JSONObject.parseObject(evtStr, QueryOperateLogEvt.class);
                queryOperateLogEvt.setPageNo(currNo);
                queryOperateLogEvt.setPageSize(currSize);
                queryOperateLogEvt.setCountTotal(true);
                showList = logService.listOperateLog(queryOperateLogEvt).getRecords();
                break;
            case ExportConstant.EXPORT_TYPE_LOGIN_LOG_LIST:
                loginLogEvt = JSONObject.parseObject(evtStr, LoginLogEvt.class);
                loginLogEvt.setPageNo(currNo);
                loginLogEvt.setPageSize(currSize);
                loginLogEvt.setCountTotal(true);
                showList = logService.listLoginLog(loginLogEvt).getRecords();
                break;

            default:
                throw new Exception("错误的导出类型");
        }
        try {

            // 声明一个工作薄
            SXSSFWorkbook book = new SXSSFWorkbook(ExportConstant.EXPORT_PAGESIZE);
            while (exportSheetNum > 0) {
                //角色的第二个sheet页重置一下导出参数
                if (exportSheetNum == 1 && ExportType.equals(ExportConstant.EXPORT_TYPE_ROLE)) {
                    sheetName = LocalMessageUtil.getMessage(EXPORT_ROLE_PERMISSION);
                    showList = roleService.getRolePermissionExport(roleEvt);
                    strEname = ExportListEnum.ROLE_PERMISSION.getExpColEn();
                    strCname = ExportListEnum.ROLE_PERMISSION.getExpColCn();
                }
                // 生成一个表格
                Sheet sheet = book.createSheet(sheetName);
                //表头
                Row titleRow = getRow(0, sheet);
                for (int i = 0; i < strCname.length; ++i) {
                    ExcelExportUtil.createCell(i, titleRow, strCname[i]);
                }
                //插入需导出的数据
                int writeRowNum = 1;
                while (showList != null) {
                    for (int i = 0; i < showList.size(); i++) {
                        // 新建行
                        Row writeRow = getRow(writeRowNum, sheet);
                        Map<String, Object> ipMap = new HashMap<>();
                        if (showList.get(i) instanceof Map) {
                            ipMap = (Map<String, Object>) showList.get(i);
                        } else {
                            ipMap = ExcelExportUtil.beanToMap(showList.get(i));
                        }
                        for (int j = 0; j < strEname.length; j++) {
                            ExcelExportUtil.createCell(j, writeRow, ipMap.get(strEname[j]));
                        }
                        writeRowNum++;
                    }
                    // 若是小于页码，则代表已经查询结束
                    if (showList.size() >= ExportConstant.EXPORT_PAGESIZE) {
                        switch (ExportType) {
                            case ExportConstant.EXPORT_TYPE_ROLE:
                                ++currSize;
                                break;
                            case ExportConstant.EXPORT_TYPE_USER:
                                userEvt.setPageNo(++currNo);
                                showList = baseQueryClient.exportUser(userEvt).getBody().getRecords();
                                break;
                            case ExportConstant.EXPORT_TYPE_NOTICE:
                                noticeEvt.setPageNo(++currNo);
                                showList = noticeService.selectInfos(noticeEvt);
                                transNoticeCode(showList);
                                break;
                            case ExportConstant.EXPORT_TYPE_OPERATE_LOG_LIST:
                                queryOperateLogEvt.setPageNo(++currNo);
                                showList = logService.listOperateLog(queryOperateLogEvt).getRecords();
                                break;
                            case ExportConstant.EXPORT_TYPE_LOGIN_LOG_LIST:
                                loginLogEvt.setPageSize(++currNo);
                                showList = logService.listLoginLog(loginLogEvt).getRecords();
                                break;
                            default:
                                throw new Exception("错误的导出类型");
                        }
                    } else {
                        showList = null;
                    }
                }
                exportSheetNum--;
            }

            File file = new File(exportFileName);
            //文件输出流
            outStream = new FileOutputStream(file);
            book.write(outStream);
            outStream.flush();
            outStream.close();
            ExcelExportUtil.download(request, response, file, exportFileName);
            file.delete();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (outStream != null) {
                try {
                    outStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    @Override
    public void exportRoleExcel(HttpServletRequest request, HttpServletResponse response, String exportFileName, Integer ExportType) throws Exception {
        int treeDeep = menuMapper.getMenuTreeDeep();
        int roleDeep = roleMapper.getRoleTreeDeep();
        List<RoleTreeVm> allRole = roleMapper.getRoleInfos();
        int exportSheetNum = 2;
        FileOutputStream outStream = null;
        String sheetName;

        try {
            // 声明一个工作薄
            SXSSFWorkbook book = new SXSSFWorkbook(ExportConstant.EXPORT_PAGESIZE);
            CellStyle titleStyle = book.createCellStyle();
            Font font = book.createFont();
            font.setBold(true);
            titleStyle.setFont(font);
            titleStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
            titleStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
            titleStyle.setFillBackgroundColor(HSSFColor.BLUE_GREY.index);
            while (exportSheetNum > 0) {
                int rowNum = strs.length;
                int colNum = strs[0].length;
                if (exportSheetNum == 2) {
                    //第一页sheet
                    sheetName = LocalMessageUtil.getMessage(EXPORT_ROLE_MANAGE);
                    LoginNameEvt evt = new LoginNameEvt();
                    evt.setLoginName("admin");
                    List<RoleTreeVm> showList = baseQueryClient.getRoleTree(evt).getBody();
                    // 生成一个表格
                    Sheet sheet = book.createSheet(sheetName);
                    //标题
                    Row titleRow = getRow(0, sheet);
                    titleRow.setHeight((short) 500);
                    sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, roleDeep - 1));
                    Cell titleCell = titleRow.createCell(0);
                    titleCell.setCellValue("角色列表");
                    titleCell.setCellStyle(titleStyle);
                    //使用递归将树存进二维数组
                    traverseRoleTree(showList, 0, 0);
                    //写数据
                    for (int row = 0; row < rowNum; row++) {
                        Row writeRow = getRow(row + 1, sheet);
                        //整行为空的话结束遍历
                        if (strs[row] == null) {
                            break;
                        }
                        for (int col = 0; col < colNum; col++) {
                            ExcelExportUtil.createCell(col, writeRow, strs[row][col]);
                        }
                    }
                }

                if (exportSheetNum == 1) {
                    //第二页sheet
                    sheetName = LocalMessageUtil.getMessage(EXPORT_ROLE_PERMISSION);
                    List<MenuTreeVm> showList = baseQueryClient.getMenuStaticData().getBody().getMenuTree();
                    // 生成一个表格
                    Sheet sheet = book.createSheet(sheetName);
                    //标题
                    Row titleRow = getRow(0, sheet);
                    titleRow.setHeight((short) 500);
                    sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, treeDeep + 2 + allRole.size()));
                    Cell titleCell = titleRow.createCell(0);
                    titleCell.setCellValue("角色权限");
                    titleCell.setCellStyle(titleStyle);
                    //表头
                    Row fieldRow = getRow(1, sheet);
                    ExcelExportUtil.createCell(0, fieldRow, "菜单名称");
                    for (int roleCol = 0; roleCol < allRole.size(); roleCol++) {
                        ExcelExportUtil.createCell(treeDeep + 2 + roleCol, fieldRow, allRole.get(roleCol).getRoleName());
                    }
                    sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, treeDeep + 1));
                    //使用递归将树存进二维数组
                    traverseMenuTree(showList, 0, 0);
                    //写数据
                    for (int row = 0; row < rowNum; row++) {
                        Row writeRow = getRow(row + 2, sheet);
                        //整行为空的话结束遍历
                        if (strs[row] == null) {
                            break;
                        }
                        for (int col = 0; col < colNum; col++) {
                            ExcelExportUtil.createCell(col, writeRow, strs[row][col]);
                        }
                    }
                }
                strs = new String[200][10 + allRole.size()];
                exportSheetNum--;
            }
            File file = new File(exportFileName);
            //文件输出流
            outStream = new FileOutputStream(file);
            book.write(outStream);
            outStream.flush();
            outStream.close();
            ExcelExportUtil.download(request, response, file, exportFileName);
            file.delete();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (outStream != null) {
                try {
                    outStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }


    @Override
    public void downloadModel(HttpServletRequest request, HttpServletResponse response, String fileName) throws Exception {
        String filePath = "/static/" + fileName;
        Resource resource = new ClassPathResource(filePath);
        BufferedInputStream fs = new BufferedInputStream(resource.getInputStream());
        /*File file = resource.getFile();
        BufferedInputStream fs  = new BufferedInputStream(new FileInputStream(file));*/

        /*BufferedInputStream fs = (BufferedInputStream)RoleController.class.getResourceAsStream(filePath);*/
        File fileNew = new File(fileName);
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(fileNew);
            int read = 0;
            while ((read = fs.read()) != -1) {
                fos.write(read);
                fos.flush();
            }
            fos.close();
            fs.close();
            ExcelExportUtil.download(request, response, fileNew, fileName);
        } catch (FileNotFoundException e) {
            logger.error("PayCheckController.doExport...导出模板未找到", e);
        } catch (IOException e) {
            logger.error("PayCheckController.doExport...获取导出模板失败", e);
        } finally {
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                    //log(e);
                }
            }
            if (fs != null) {
                try {
                    fs.close();
                } catch (IOException e) {
                    //log(e);
                }
            }
        }
    }

    @Override
    public ServiceResp importData(MultipartFile file, ImportEnum importEnum, ImportEnum notNullEnum) {
        String originalFilename = file.getOriginalFilename();
        // 初始化导入日志，状态为进行中（-1）
        CsSmImportLogD csSmImportLogD = new CsSmImportLogD();
        csSmImportLogD.setFilename(originalFilename);
        csSmImportLogD.setStatus(-1);
        csSmImportLogD.setCreatedUser(SecurityUtils.getCurrentUserLogin().get());
        csSmImportLogD.setCreatedTime(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now()));
        csSmImportLogDMapper.insert(csSmImportLogD);
        try {
            String allStr = "";
            String[] importColCn = importEnum.getExpColCn();
            String[] importColEn = importEnum.getExpColEn();
            String[] notNullColCn = {};
            String[] notNullColEn = {};
            if (notNullEnum != null) {
                notNullColCn = notNullEnum.getExpColCn();
                notNullColEn = notNullEnum.getExpColEn();
            }
            logger.info(file.getSize() + "");
            logger.info(file.getName() + "--" + originalFilename + "--" + file.getContentType());
            InputStream is = file.getInputStream();
            Workbook book = new XSSFWorkbook(is);
            Sheet sheet = book.getSheetAt(0);
            Row rowHead = sheet.getRow(0);
            int rows = sheet.getLastRowNum();
            // int column = rowHead.getPhysicalNumberOfCells();
            // int wrongNum = 0;
            List<Map<String, Object>> importList = new ArrayList<>();
            // 校验第一行标题
            for (int col = 0; col < importColCn.length; col++) {
                String temp;
                try {
                    Cell cell = rowHead.getCell(col);
                    temp = cell.getStringCellValue();
                } catch (Exception e) {
                    logger.error(importEnum.getRemark() + "->导入模板错误", e);
                    csSmImportLogD.setStatus(0);
                    csSmImportLogD.setRemark("导入错误的模板");
                    csSmImportLogDMapper.updateById(csSmImportLogD);
                    return ServiceResp.getInstance().error("导入模板错误");
                }
                if (!temp.trim().equals(
                        importColCn[col])) {
                    logger.error(importEnum.getRemark() + "->导入模板错误");
                    csSmImportLogD.setStatus(0);
                    csSmImportLogD.setRemark("导入模板错误");
                    csSmImportLogDMapper.updateById(csSmImportLogD);
                    return ServiceResp.getInstance().error("导入模板错误");
                }
            }
            for (int index = 3; index < (rows + 1); index++) {
                Row row = sheet.getRow(index);
                if (row == null) {
                    continue;
                }
                Map<String, Object> params = new HashMap<>();
                for (int i = 0; i < importColEn.length; i++) {
                    params.put(importColEn[i], ExcelExportUtil.getCellValue(row.getCell(i)));
                    params.put("index", index + 1);
                }
                importList.add(params);
            }
            // 校验非空
            Map<String, Object> params;
            List<String> str = Lists.newArrayList();
            List<Map<String, Object>> importDatas = Lists.newArrayList();
            for (int i = 0; i < importList.size(); i++) {
                allStr = allStr + "第" + (i + 4) + "行数据出错：";
                params = importList.get(i);
                //非空字段验证
                for (int j = 0; j < notNullColEn.length; j++) {
                    if (StringUtils.isBlank(String.valueOf(
                            params.get(notNullColEn[j])))) {
                        //str += notNullColCn[j] + "不能为空！";
                        str.add(notNullColCn[j] + "不能为空！");
                    }
                }
                if (CollectionUtils.isNotEmpty(str)) {
                    allStr += StringUtils.join(str, ",");
                    str.clear();
                    allStr += "\n";
                } else {
                    importDatas.add(params);
                    allStr = "";
                }
            }
            if (!"".equals(allStr)) {
                csSmImportLogD.setStatus(0);
                csSmImportLogD.setRemark(allStr);
                csSmImportLogDMapper.updateById(csSmImportLogD);
                return ServiceResp.getInstance().error(allStr);
            }
            //判断是否有导入数据
            /*if (importList == null || importList.size() == 0) {
                csSmImportLogD.setRemark("未识别出需要导入的数据,请根据模板填写内容");
                csSmImportLogDMapper.updateById(csSmImportLogD);
                throw new Exception("未识别出需要导入的数据,请根据模板填写内容");
            }*/
            // 插入语句
            switch (importEnum.getValue()) {
                case ExportConstant.EXPORT_TYPE_ROLE:
                    String checkStr = roleService.importRole(importDatas, csSmImportLogD);
                    if (StringUtils.isNotBlank(checkStr)) {
                        return ServiceResp.getInstance().error(checkStr);
                    }
                    break;
                case ExportConstant.EXPORT_TYPE_USER:
                    String checkStr2 = userService.importUser(importDatas, csSmImportLogD);
                    if (StringUtils.isNotBlank(checkStr2)) {
                        return ServiceResp.getInstance().error(checkStr2);
                    }
                    break;
                default:
                    csSmImportLogD.setStatus(0);
                    csSmImportLogD.setRemark("导入类型错误");
                    csSmImportLogDMapper.updateById(csSmImportLogD);
                    throw new Exception("导入类型错误");
            }
        } catch (Exception e) {
            logger.error(importEnum.getRemark() + "->导入失败", e);
            e.printStackTrace();
            csSmImportLogD.setStatus(0);
            csSmImportLogD.setRemark("导入失败，系统错误");
            csSmImportLogDMapper.updateById(csSmImportLogD);
            return ServiceResp.getInstance().error(e.getMessage());
        }
        csSmImportLogD.setStatus(1);
        csSmImportLogD.setRemark("导入成功");
        csSmImportLogDMapper.updateById(csSmImportLogD);
        return ServiceResp.getInstance().success(true, "导入成功");
    }

    public void transNoticeCode(List<NoticeVm> noticeList) {
        NoticeCodeList noticeCodeList = noticeService.getCodeList();
        List<Map<String, Object>> stateList = noticeCodeList.getStateList();
        List<Map<String, Object>> typeList = noticeCodeList.getTypeList();
        for (NoticeVm vm :
                noticeList) {
            vm.setState(getDescName(vm.getState(), stateList));
            vm.setType(getDescName(vm.getType(), typeList));
        }
    }

    public void parseUserList(List<QueryUserVm> userVmList) {
        for (QueryUserVm vm :
                userVmList) {
            if (StringUtils.isNotBlank(vm.getFullRegionName())) {
                vm.setFullRegionName(vm.getFullRegionName().split("/")[0]);
            } else {
                vm.setFullRegionName("空");
            }
            if ("全国".equals(vm.getFullRegionName())) {
                vm.setFullRegionName("集团");
            }
        }
    }

    public String getDescName(String value, List<Map<String, Object>> codeList) {
        for (Map<String, Object> code :
                codeList) {
            if (ObjectUtils.equals(code.get("value"), value)) {
                return String.valueOf(code.get("descname"));
            }
        }
        return value;
    }


    public int traverseRoleTree(List<RoleTreeVm> childList, int col, int row) {
        int nowRow = 0;
        int returnRow = 0;
        int blankRow = 0;
        //遍历节点
        for (int i = 0; i < childList.size(); i++) {
            //获取到当前结点
            RoleTreeVm vm = childList.get(i);
            if (returnRow == 0) {
                nowRow = row + i + blankRow;
            } else {
                nowRow = returnRow;
            }
            //写数据
            strs[nowRow][col] = vm.getRoleName();
            returnRow = 0;
            if (vm.getChildren() != null && vm.getChildren().size() > 0) {
                returnRow = traverseRoleTree(vm.getChildren(), col + 1, nowRow);
                blankRow = returnRow - row - i - 1;
                nowRow = returnRow - 1;
            }
        }
        return (nowRow + 1);
    }


    public int traverseMenuTree(List<MenuTreeVm> childList, int col, int row) {
        int nowRow = 0;
        int returnRow = 0;
        int blankRow = 0;
        //遍历节点
        for (int i = 0; i < childList.size(); i++) {
            //获取到当前结点
            MenuTreeVm vm = childList.get(i);
            if (returnRow == 0) {
                nowRow = row + i + blankRow;
            } else {
                nowRow = returnRow;
            }
            //写数据
            strs[nowRow][col] = vm.getNameCn();
            returnRow = 0;
            if (vm.getChildren() != null && vm.getChildren().size() > 0) {
                returnRow = traverseMenuTree(vm.getChildren(), col + 1, nowRow);
                blankRow = returnRow - row - i - 1;
                nowRow = returnRow - 1;
            } else {
                //如果没有子节点的话就写权限
                int treeDeep = menuMapper.getMenuTreeDeep();
                List<RoleTreeVm> allRole = roleMapper.getRoleInfos();
                List<Long> roleWithMenu = menuMapper.getRoleByMenuId(vm.getMenuId());
                strs[nowRow][treeDeep + 1] = vm.getNameEn();
                //先全部赋值为0
                for (int m = 0; m < allRole.size(); m++) {
                    strs[nowRow][treeDeep + m + 2] = "0";
                }
                for (int k = 0; k < allRole.size(); k++) {
                    for (Long roleId : roleWithMenu) {
                        if (roleId.equals(allRole.get(k).getRoleId())) {
                            strs[nowRow][treeDeep + k + 2] = "1";
                            break;
                        }
                    }
                }
            }
        }
        return (nowRow + 1);
    }

    private void parseOperateLogDataByUser(List<Map<String, Object>> list) {

    }


}
